package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.SupplierBean;
import com.project.dto.SupplierDto;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import com.project.util.ConvertBeanUtil;
import com.project.util.MD5Encryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.security.NoSuchAlgorithmException;

@Service
@Transactional
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private ISupplierMapper supplierMapper;

    @Override
    public SupplierDto login(String userName, String password) throws NoSuchAlgorithmException {
        QueryWrapper<SupplierBean> qw = new QueryWrapper<>();
        qw.eq("s_userName", userName);
        qw.eq("s_password", MD5Encryptor.encrypt(password));
        SupplierBean supplierBean = supplierMapper.selectOne(qw);
        if (supplierBean != null) {//找到了
            return ConvertBeanUtil.copy(supplierBean, SupplierDto.class);
        }
        return null;
    }

    @Override
    public SupplierBean findById(Long supplierId) {
        return supplierMapper.selectById(supplierId);
    }
}
